package com.ruoyi.web.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.DrugEnterprise;
import com.ruoyi.web.service.IDrugEnterpriseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品药企Controller
 * 
 * @author drx
 * @date 2025-05-13
 */
@Controller
@RequestMapping("/web/enterprise")
@Api(tags = "药品药企")
public class DrugEnterpriseController extends BaseController
{
    private String prefix = "web/enterprise";

    @Autowired
    private IDrugEnterpriseService drugEnterpriseService;

    @RequiresPermissions("web:enterprise:view")
    @GetMapping()
    public String enterprise()
    {
        return prefix + "/enterprise";
    }

    /**
     * 查询药品药企列表
     */
    @RequiresPermissions("web:enterprise:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询药品药企列表")
    public TableDataInfo list(DrugEnterprise drugEnterprise)
    {
        startPage();
        List<DrugEnterprise> list = drugEnterpriseService.selectDrugEnterpriseList(drugEnterprise);
        return getDataTable(list);
    }

    /**
     * 导出药品药企列表
     */
    @RequiresPermissions("web:enterprise:export")
    @Log(title = "药品药企", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出药品药企列表")
    public AjaxResult export(DrugEnterprise drugEnterprise)
    {
        List<DrugEnterprise> list = drugEnterpriseService.selectDrugEnterpriseList(drugEnterprise);
        ExcelUtil<DrugEnterprise> util = new ExcelUtil<DrugEnterprise>(DrugEnterprise.class);
        return util.exportExcel(list, "药品药企数据");
    }

    /**
     * 新增药品药企
     */
    @GetMapping("/add")
    @ApiOperation("新增药品药企")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存药品药企
     */
    @ApiOperation("新增保存药品药企")
    @RequiresPermissions("web:enterprise:add")
    @Log(title = "药品药企", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DrugEnterprise drugEnterprise)
    {
        return toAjax(drugEnterpriseService.insertDrugEnterprise(drugEnterprise));
    }

    /**
     * 修改药品药企
     */
    @ApiOperation("修改药品药企")
    @RequiresPermissions("web:enterprise:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DrugEnterprise drugEnterprise = drugEnterpriseService.selectDrugEnterpriseById(id);
        mmap.put("drugEnterprise", drugEnterprise);
        return prefix + "/edit";
    }

    /**
     * 修改保存药品药企
     */
    @ApiOperation("修改保存药品药企")
    @RequiresPermissions("web:enterprise:edit")
    @Log(title = "药品药企", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DrugEnterprise drugEnterprise)
    {
        return toAjax(drugEnterpriseService.updateDrugEnterprise(drugEnterprise));
    }

    /**
     * 删除药品药企
     */
    @ApiOperation("删除药品药企")
    @RequiresPermissions("web:enterprise:remove")
    @Log(title = "药品药企", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(drugEnterpriseService.deleteDrugEnterpriseByIds(ids));
    }
}
